﻿@model List<Comment>
    @using NITASA.Data
    @using GridMvc.Html
    @{
        ViewBag.Title = "Abusive Comments";
    }
    
    <div class="main-content">
        <div class="container-fluid padded">
            @if (TempData["AbusiveAction"] != null)
            {
                <div class="alert alert-success">
                    <button class="close" data-dismiss="alert" type="button">
                        ×
                    </button>
                    @TempData["AbusiveAction"]
                </div>
            }
            <div class="row-fluid">
                <div class="span12">
                    <div class="box">
                        <div class="box-header">
                            <ul class="nav nav-tabs nav-tabs-left">
                                <li><a href="@Url.Action("List", "Comment")">All Comments</a></li>
                                <li class="active"><a href="@Url.Action("Abusive", "Comment")">Abusive Comments</a></li>
                            </ul>
                        </div>
                        <div class="box-content padded">
                            <div class="tab-content">
                                <div class="tab-pane active">
                                    <div class="row-fluid">
                                        <div class="span12">
                                            @if (Model.Count() > 0)
                                            {
                                                <div class="box">
                                                    <div class="box-content">
                                                        @Html.Grid(Model).Columns(columns =>
                                                        {
                                                           columns.Add(x => x.UserName).Titled("Name").Sortable(true).Filterable(true);
                                                           columns.Add(x => x.Description).Titled("Comment").Sortable(true).Filterable(true);
                                                           columns.Add(x => x.AbusedBy).Titled("Complaint by").Sortable(true).Filterable(true);
                                                           columns.Add(x => x.AbusedReason).Titled("Reason").Sortable(true).Filterable(true);
                                                           columns.Add().SetWidth(140).RenderValueAs(x =>
                                                               @Html.Raw("<form action=\"" + @Url.Action("AbusiveAction", "Comment") + "\" method=\"post\">" +
                                                               @Html.AntiForgeryToken() +
                                                               "<input type=\"submit\" class=\"btn btn-mini btn-red delete\" name=\"delete\" value=\"Delete\" />" +
                                                               "<input type=\"hidden\" name=\"id\" value=\"" + x.ID + "\" />" +
                                                               "<input type=\"submit\" class=\"btn btn-mini btn-green un-abusive\"  name=\"unabusive\" value=\"Un-Abused\" />" +
                                                               "</form>")).Sanitized(false).Encoded(false).Titled("Actions");
                                                        }).WithPaging(10, 5).WithMultipleFilters()
                                                    </div>
                                                </div>
                                            }
                                            else
                                            {
                                                <div class="padded">
                                                    No Comments Found.
                                                </div>
                                            }
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <script>
        $(document).ready(function () {
            $("input.btn").click(function () {
                if ($(this).hasClass("delete")) {
                    if (confirm("Are you sure you want to delete this comment ?")) {
                        $(this).closest("form").submit();
                    }
                    else {
                        return false;
                    }
                }
                else {
                    if (confirm("Are you sure you want to mark this comment as un-abusive ?")) {
                        $(this).closest("form").submit();
                    }
                    else {
                        return false;
                    }
                }
            });
        });
    </script>
